var x_t,y_t;
global.back_tile_dim = 32
//visible = 0
width = room_width/global.back_tile_dim
height = room_height/global.back_tile_dim
draw = false
global.town_sites[1,1] = 0
global.town_sites_num = 0
back_tiles[1,1] = 0
b_num = 0
myGrid = ds_grid_create(width+1,height+1)
InitNoiseHelper()
CreateNoise()//scr_noisegrid()//rough_grid = scr_noisegrid(width,height,choose( 3,4,5,6 ), 4, 1, irandom( 32000 ))
show_debug_message('width set to ' + string(width) + ' and height set to ' + string(height))

//astar_setcellcostdir(3,3,3,10000)
for (var i=0;i<=width;i+=1)
    {
    for (var j=0;j<=height;j+=1)
        {
        //obj = instance_create(i*global.back_tile_dim,j*global.back_tile_dim,obj_back)
        //tile_add(bck_grass,0,0,global.back_tile_dim,global.back_tile_dim,i*global.back_tile_dim,j*global.back_tile_dim,3)
        b_height = ds_grid_get( myGrid, i, j )*0.5+0.5
        astar_setcellcost(i*global.back_tile_dim,j*global.back_tile_dim,round(b_height*200))
        //obj.height = ds_grid_get( myGrid, i, j )*0.5+0.5
        if b_height > 0.45 and b_height < 0.60
            {
            x_t = i*global.back_tile_dim
            y_t = j*global.back_tile_dim
            if choose(0,1,2) = 0
            if (x_t > 400) and (x_t < (room_width - 400))
            if (y_t > 400) and (y_t < (room_height - 400))
                {//obj.col = c_white
            
                global.town_sites[global.town_sites_num,1] = x_t
                global.town_sites[global.town_sites_num,2] = y_t
                global.town_sites_num += 1}
            }
        b = tile_add(bck_grass,0,0,global.back_tile_dim,global.back_tile_dim,i*global.back_tile_dim,j*global.back_tile_dim,3)
        col = merge_color(13674,8454143,b_height)
        tile_set_blend(b,col)
        ////////////////////////.\\\\\\\\\\\\\\\\\\\\\\\\
        //WARNING! THE DEBUG LOG IS SUPER FUCKCING SLOW /
        //\\\\\\\\\\\\\\\\\\\\\\.////////////////////////
        //show_debug_message('tile #'+string(num)+ ' created at (' + string(i*global.back_tile_dim) + ',' +string(j*global.back_tile_dim) + ') ' + string(height))
        }
    }
    

//screen_save(working_directory+'/back.bmp')

/*back_surface = surface_create(room_width,room_height)
view_surface_id[1] = back_surface
surface_set_target(back_surface)
for (var i=0;i<=b_num-1;i+=1)
    {
    draw_rectangle(back_tiles[i,0],back_tiles[i,1],back_tiles[i,0]+global.back_tile_dim,back_tiles[i,1]+global.back_tile_dim,false)
    //show_debug_message('Drawing background tile #' + string(b_num))
    }
surface_reset_target()
back = background_create_from_surface(back_surface,0,0,room_width,room_height,false,false)
//background_save(back,'back.png')
surface_free(back_surface)
room_set_background(room,0,true,false,back,0,0,false,false,0,0,1)*/
//global.road_map = mp_grid_create(0,0,round(room_width/16),round(room_height/16),16,16)
//mp_grid_add_instances(global.road_map,obj_impass,0)
//with (obj_impass) {instance_destroy()}
ds_grid_destroy(myGrid)
